import time
from PySide6.QtCore import QObject, Signal
from pynput import mouse

class Listener_Mouse_Position(QObject):
    finished = Signal()
    x_y = Signal(tuple)
    dx_dy = Signal(tuple)

    def __init__(self):
        super().__init__()
        self.mouse_listener = None

    def start(self):
        print(f'开始监听鼠标位置')
        self.mouse_listener = mouse.Listener(
            on_click=self.on_click,
            on_scroll=self.on_scroll
        )
        self.mouse_listener.start()
        self.mouse_listener.join()
        self.finished.emit()

    def on_click(self,x,y,button,modifiers):
        print(f'点击位置{x},{y}')
        self.x_y.emit((x,y))
        self.mouse_listener.stop()

    def on_scroll(self,x,y,dx,dy):
        print(f'滚轮滚动：{dx},{dy}')
        self.dx_dy.emit((dx,dy))
        self.mouse_listener.stop()
